package ar.edu.uba.fi.jmit.aspecter.monitor.objectCount;

import ar.edu.uba.fi.jmit.aspecter.core.WeavingInstrumentorImpl;
import ar.edu.uba.fi.jmit.aspecter.core.exception.AspecterRuntimeException;

public class ObjectCountInstrumentor extends WeavingInstrumentorImpl {
	
	private String className;
	
	private String priority = null;
	
	public ObjectCountInstrumentor(Class<?> clazz, String monitorName, String priority) {
		this(clazz.getName(), monitorName, priority);
	}
	
	public ObjectCountInstrumentor(Class<?> clazz, String monitorName) {
		this(clazz.getName(), monitorName);
	}
	
	public ObjectCountInstrumentor(String className, String monitorName, String priority) {
		super(monitorName);
		this.className = className;
		this.priority = priority;
		init();
	}
	
	public ObjectCountInstrumentor(String className, String monitorName) {
		super(monitorName);
		this.className = className;
		init();
	}

	private void init() {
		try {
			ObjectCountNewInstanceInterceptor interceptor = null;
			if(priority!=null && !"".equals(priority)) {
				interceptor = new ObjectCountNewInstanceInterceptor(className, getMonitorName(), priority);
			}else {
				interceptor = new ObjectCountNewInstanceInterceptor(className, getMonitorName());
			}
			addInterceptor(interceptor);
		} catch (ClassNotFoundException e) {
			throw new AspecterRuntimeException("Class for name " + className + " not found", e);
		}
	}
}
